home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16_Src.lha / Python16_Source / Python / dynload_os2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-03  |  957 b   |  46 lines

  1. /* Support for dynamic loading of extension modules */
  2.  
  3. #define  INCL_DOSERRORS
  4. #define  INCL_DOSMODULEMGR
  5. #include <os2.h>
  6.  
  7. #include "Python.h"
  8. #include "importdl.h"
  9.  
  10.  
  11. const struct filedescr _PyImport_DynLoadFiletab[] = {
  12.     {".pyd", "rb", C_EXTENSION},
  13.     {".dll", "rb", C_EXTENSION},
  14.     {0, 0}
  15. };
  16.  
  17. dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
  18.                     const char *pathname, FILE *fp)
  19. {
  20.     dl_funcptr p;
  21.     APIRET  rc;
  22.     HMODULE hDLL;
  23.     char failreason[256];
  24.     char funcname[258];
  25.  
  26.     rc = DosLoadModule(failreason,
  27.                sizeof(failreason),
  28.                pathname,
  29.                &hDLL);
  30.  
  31.     if (rc != NO_ERROR) {
  32.         char errBuf[256];
  33.         sprintf(errBuf,
  34.             "DLL load failed, rc = %d: %s",
  35.             rc, failreason);
  36.         PyErr_SetString(PyExc_ImportError, errBuf);
  37.         return NULL;
  38.     }
  39.  
  40.     sprintf(funcname, "init%.200s", shortname);
  41.     rc = DosQueryProcAddr(hDLL, 0L, funcname, &p);
  42.     if (rc != NO_ERROR)
  43.         p = NULL; /* Signify Failure to Acquire Entrypoint */
  44.     return p;
  45. }
  46.